//Solder Spool Stand - Terence Ang - 11 Aug 2014.

// 0 : display all
// 1 : base
// 2 : solder box
// 3 : spool rod

print = 0;

$fn = 128;
spool_width = 40;
spool_od = 50;
spool_id = 20;

spool_rod_od = 18;

stand_wall_thickness = 7;
stand_wall_offset = 6;

pen_d = 15;
pen_base = pen_d + 3;
pen_hole_offset = 1;
pen_base_height = 44;
pen_base_depth = 10;

solder_stand_width = spool_width + stand_wall_offset + stand_wall_thickness;
solder_stand_depth = spool_od + stand_wall_offset + stand_wall_thickness;
solder_stand_height = spool_od + stand_wall_thickness * 2;
base_width = solder_stand_width + pen_base;

lip_size = stand_wall_thickness /2;

module pen_holder(){
		difference(){
				//base
				translate([0, 0, 0]) cube([solder_stand_width, solder_stand_depth, stand_wall_thickness / 4], center = true);	

				//base cut
				 translate([0, 0, 0])
				cube([solder_stand_width - stand_wall_offset, solder_stand_depth - stand_wall_offset, solder_stand_height], center = true);
			}

		//lip
		difference(){
				translate([0, 0,lip_size/2])
				cube([solder_stand_width - lip_size, solder_stand_depth - lip_size, lip_size /2], center = true);

				//base cut
				translate([0, 0, 0])
				cube([solder_stand_width - stand_wall_offset, solder_stand_depth - stand_wall_offset, solder_stand_height], center = true);
			}

		difference(){
				//pen_base
				translate([solder_stand_width /2 + pen_base /2, 0, pen_base_height/2 - stand_wall_thickness / 8]) cube([pen_base, solder_stand_depth, pen_base_height], center = true);
				//pen hole cut
				translate([solder_stand_width /2 + pen_base /2, 22.5, pen_base_height]) 
						cylinder(d = pen_d + pen_hole_offset, h = solder_stand_height - stand_wall_thickness/4, center = true);

				// pcb slot cut
				translate([solder_stand_width /2 + pen_base /2 - pen_hole_offset, -15, pen_base_height/2 + stand_wall_thickness / 8]) cube([pen_base -2, (spool_od + stand_wall_offset), pen_base_height], center = true);

				// pen base cut
				translate([solder_stand_width /2 + pen_base /2 - pen_hole_offset, -8, 0]) cube([pen_base -2, (spool_od + stand_wall_offset)*.75, pen_base_height], center = true);

				//bevel cut
				translate([solder_stand_width /2 + pen_base /2,-35,42]) rotate([60,0,0]) cube([pen_base + 2.5, (spool_od + stand_wall_offset) / 2+ 40, 44], center = true);
			}

	difference(){
		translate([pen_base / 2, solder_stand_depth/2 + pen_base_depth/2, pen_base_height/2 -stand_wall_thickness / 8]) cube([solder_stand_width + pen_base, pen_base_depth, pen_base_height], center = true);	
		translate([pen_base / 2, solder_stand_depth/2 + pen_base_depth/2-1, pen_base_height/2 + stand_wall_thickness / 8]) cube([solder_stand_width + pen_base -3, pen_base_depth - 2, pen_base_height], center = true);	
		}

		translate([-10 , solder_stand_depth/2 + pen_base_depth/2, pen_base_height/2 -stand_wall_thickness / 8]) cube([2, pen_base_depth, pen_base_height], center = true);	
		translate([4 , solder_stand_depth/2 + pen_base_depth/2, pen_base_height/2 -stand_wall_thickness / 8]) cube([2, pen_base_depth, pen_base_height], center = true);	
}



module solder_stand()
	{
		solder_stand_width = spool_width + stand_wall_offset + stand_wall_thickness;
		solder_stand_depth = spool_od + stand_wall_offset + stand_wall_thickness;
		solder_stand_height = spool_od + stand_wall_thickness * 2;

		lip_size = stand_wall_thickness /2;



		difference(){

			union(){
				cube([solder_stand_width, solder_stand_depth, solder_stand_height], center = true);
				//lip
				translate([0, 0, solder_stand_height / 2])
				cube([solder_stand_width - lip_size, solder_stand_depth - lip_size, lip_size /2], center = true);
				} //union

			//center cut
			translate( [0, 0, stand_wall_thickness + stand_wall_offset /4]) 
				cube([solder_stand_width - stand_wall_thickness, solder_stand_depth - stand_wall_thickness, solder_stand_height + stand_wall_offset], center = true);

			//front cut
			translate( [0,-spool_od , spool_od / 1.5 ]) 
				cube([spool_width + stand_wall_offset, spool_od + stand_wall_offset, spool_od + stand_wall_thickness * 2], center = true);

			//spool slot
			translate([0,0,3]) rotate([30,0,0]) 
				union(){
					rotate([0,90,0]) 
						cylinder(d = spool_rod_od, h = solder_stand_width - stand_wall_thickness / 2, center = true);
						translate( [0,0 , solder_stand_height / 2]) 
							cube([solder_stand_width - stand_wall_thickness / 2 , spool_rod_od, solder_stand_height], center = true);
				}//union

			//front bevel
			translate( [0,-spool_od /2-8 ,spool_od / 2]) 
				rotate([-25,0,0]) cube([solder_stand_width + 2, spool_rod_od +3, solder_stand_height +100], center = true);

			translate( [0,0 ,40]) rotate([-145,0,0]) 
				 cube([solder_stand_width - stand_wall_thickness/2, spool_rod_od +3, 5], center = true);

			translate( [0,-8.5 ,40]) rotate([90,0,0]) 
				cube([solder_stand_width - stand_wall_thickness/2, spool_rod_od +3, 5], center = true);
				
			//solder hole
			translate( [0,-spool_od /2 ,-10])  rotate([120,0,0]) cylinder(d = 2 , h = spool_width +7, center = true);
			translate( [0,-spool_od /2 ,-16])  rotate([-120,0,0]) cylinder(d = 2 , h = spool_width -4, center = true);

			translate( [0,-solder_stand_depth/2, -13])  cube([2,10,2], center = true);

			//bottom cut
			translate([0,0,- solder_stand_height / 2])
				union(){
					difference(){
						cube([solder_stand_width - lip_size + .5, solder_stand_depth - lip_size + .5, lip_size], center = true);
						cube([solder_stand_width - stand_wall_offset -.5, solder_stand_depth - stand_wall_offset - .5, solder_stand_height], center = true);
						}
					}						
			}//difference
	}

module spool_rod(spool_rod_d)
	{
		color("cyan") rotate([0,90,0]) cylinder(d = spool_rod_d -.5, h = spool_width + stand_wall_offset + stand_wall_thickness /2 -1.8 , center = true);
	}

module spool_adapter(spool_rod_d, od){
	difference(){
		union(){
			cylinder(d= od + 5, h=2, center=true); 
			translate([0,0,3]) cylinder(d=od,h=8, center=true); 
			}
			cylinder(d=spool_rod_d, h=16, center=true); 
		}
}

module solder_spool(s_width,s_id, s_od)
	{

		color("blue") rotate([0,90,0]) difference(){
			 cylinder(d = s_od, h = s_width, center = true);
			difference(){
				cylinder(d = s_od + 2, h = s_width - 2, center = true);
				cylinder(d = s_od -15, h = s_width - 2, center = true);
				}
			cylinder(d=20, h = s_width  + 5, center = true);
			}
	}	

//start

*difference(){
color("red") translate([0, 0, 0]) solder_stand();
				//base cut
				 translate([0, 0, -5])
				cube([solder_stand_width - stand_wall_offset, solder_stand_depth - stand_wall_offset, solder_stand_height], center = true);
}

if (!print || print == 1) translate([0,0,-solder_stand_height/2 + stand_wall_thickness / 8]) pen_holder();

if (!print || print == 2) solder_stand();

if (print == 3) spool_adapter(18,20.5);

if (!print || print == 4) spool_rod(18);

if (!print || print == 0) solder_spool(spool_width, spool_id, spool_od );

